package com.gitee.lw114514.tliasweb.controller;

import com.gitee.lw114514.tliasweb.pojo.Clazz;
import com.gitee.lw114514.tliasweb.pojo.ClazzQueryParam;
import com.gitee.lw114514.tliasweb.pojo.PageResult;
import com.gitee.lw114514.tliasweb.pojo.Result;
import com.gitee.lw114514.tliasweb.service.ClazzsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/clazzs")
@Slf4j
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;

    /**
     * 分页查询所有班级信息
     */
    @GetMapping
    public Result list(ClazzQueryParam clazzQueryParam){
        Integer page=clazzQueryParam.getPage();
        Integer pageSize=clazzQueryParam.getPageSize();
        String name=clazzQueryParam.getName();
        LocalDate begin=clazzQueryParam.getBegin();
        LocalDate end=clazzQueryParam.getEnd();

        log.info("查询所有班级信息:名字：{},开班时间{}，结课时间：{},页数{},页大小{}",
                name, begin, end, page, pageSize);
        PageResult<Clazz> clazzList = clazzsService.list(clazzQueryParam);
        return Result.success(clazzList);
    }

    @GetMapping("/list")
    public Result list(){
        log.info("查询所有班级信息");
        List<Clazz> clazzList = clazzsService.listAll();
        return Result.success(clazzList);
    }


}
